package com.example.back.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.back.service.DrugService;
import com.example.common.support.Result;
import com.example.common.utils.RequestHelp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author wxy
 * @Date 2021/1/13 14:20
 * @Version 1.0
 */
@RestController
@Api(tags = "商品订单")
@RequestMapping("/api/Drug")
public class DrugController {
    @Resource
    private DrugService drugService;

    @ApiOperation(value = "商品订单", notes = "商品订单")
    @PostMapping(value = "/List")
    public Result<Map<String, Object>> List(HttpServletRequest request) {
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        String orderno = Jo.getString("orderno");
        String consignee = Jo.getString("consignee");
        String consigneeTel = Jo.getString("consigneeTel");
        byte orderstatus = Jo.getByteValue("orderstatus"); 
        int ltype = Jo.getIntValue("ltype");

        int page = Jo.getIntValue("page");
        int limit = Jo.getIntValue("limit"); 
        return Result.success(drugService.List(orderno, consignee, consigneeTel, orderstatus, ltype, page, limit));
    }

    @ApiOperation(value = "", notes = "")
    @PostMapping(value = "/OrderExportXls")
    public Result<Object> OrderExportXls(HttpServletRequest request) {
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        String orderno = Jo.getString("orderno");
        String consignee = Jo.getString("consignee");
        String consigneeTel = Jo.getString("consigneeTel");
        byte orderstatus = Jo.getByteValue("orderstatus"); 
        int ltype = Jo.getIntValue("ltype");

        return Result.success(drugService.OrderExportXls(orderno, consignee, consigneeTel, orderstatus, ltype));
    }

    @ApiOperation(value = "订单详情", notes = "订单详情")
    @PostMapping(value = "/Detail")
    public Result<Map<String, Object>> Detail(HttpServletRequest request) {
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        String orderno = Jo.getString("orderno");
        return Result.success(drugService.Detail(orderno));
    }
    
    @ApiOperation(value = "物流订单确认发货、自提订单确认提货", notes = "物流订单确认发货、自提订单确认提货")
    @PostMapping(value = "/OrderSend")
    public Result<Boolean> OrderSend(HttpServletRequest request) {
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        String orderno = Jo.getString("orderno");
        String company = Jo.getString("company");
        String companyCode = Jo.getString("companyCode");
        String waybill = Jo.getString("waybill");
        return Result.success(drugService.OrderSend(orderno,company,companyCode,waybill));
    }
}
